<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>密码修改</title>
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>

    <link rel="stylesheet" href="../js/libs/sui/sm.min.css">
    <link rel="stylesheet" href="../js/libs/sui/sm-extend.min.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <link rel="stylesheet" href="../less/main.css"/>

    <script type='text/javascript' src='../js/libs/jquery-3.1.0.min.js' charset='utf-8'></script>
    <script type="text/javascript">
        var Zepto = jQuery;
    </script>
    <script type='text/javascript' src='../js/libs/sui/sm.js' charset='utf-8'></script>
    <script type='text/javascript' src='../js/libs/sui/sm-extend.min.js' charset='utf-8'></script>
    <script src="../js/libs/juicer-min.js"></script>
    <script src="../js/libs/jquery.md5.js"></script>
    <script src="../js/api.js"></script>
    <script src="../js/utils.js"></script>
    <script src="../js/common.js"></script>
</head>
<body>
<div class="content modify-password bg-default p-t22">
    <!--头部-->
    <div class="head-no-toolbar bg-self-green no-left-icon">
        <span class="icon iconfont c-white p-l" onclick="javascript:closeWin()">&#xe61f;</span>
        <span class="c-white t-center">修改密码</span>
    </div>
    <div class="list-block">
        <ul>
            <!-- Text inputs -->
            <li>
                <div class="item-content">
                    <div class="item-inner">
                        <div class="item-input">
                            <input id="origin-pwd" type="password" placeholder="请输入原始密码">
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-inner">
                        <div class="item-input">
                            <input id="new-f-pwd" type="password" placeholder="请输入新密码">
                        </div>
                    </div>
                </div>
            </li>

            <!-- Select -->
            <li>
                <div class="item-content">
                    <div class="item-inner">
                        <div class="item-input">
                            <input id="new-s-pwd" type="password" placeholder="请确认新密码">
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
    <div class="content-block">
        <div class="row">
            <div class="col-100"><a id="update-btn" class="button button-big button-round button-fill bg-self-green">确定</a></div>
        </div>
    </div>
</div>
<script>
    apiready=function(){
        juicer.set({
            'tag::operationOpen': '{@',
            'tag::operationClose': '}',
            'tag::interpolateOpen': '&{',
            'tag::interpolateClose': '}',
            'tag::noneencodeOpen': '$${',
            'tag::noneencodeClose': '}',
            'tag::commentOpen': '{#',
            'tag::commentClose': '}',
            'strip': false,
            'cache': false
        });

        $("#update-btn").click(function(){
            updatePwd();
        });

        function updatePwd() {
            var originPwd = $api.trim($("#origin-pwd").val());
            var newFirstPwd = $api.trim($("#new-f-pwd").val());
            var newSecondPwd = $api.trim($("#new-s-pwd").val());

            if (getStrRealLength(originPwd) == 0) {
                toast("请输入原始密码");
                return;
            }
            if (getStrRealLength(newFirstPwd) == 0 || getStrRealLength(newSecondPwd) == 0) {
                toast("请输入新密码");
                return;
            }

            if (newFirstPwd != newSecondPwd) {
                toast("新密码不一致");
                return;
            }

            var userInfo = getLoginUserInfo();
            if(isObject(userInfo)){

                var originmd5Pwd = $.md5(originPwd);
                if (originmd5Pwd != userInfo.PWD) {
                    toast("原始密码不正确");
                    return;
                }

                //更新密码
                var staffId = userInfo.STAFF_ID;
                var newmd5Pwd = $.md5(newFirstPwd);
                var sql = "UPDATE su_staff SET PWD='" + newmd5Pwd + "' WHERE STAFF_ID='" + staffId + "'";
                dbExecute(sql, true, function (ret, err) {
                    if (isObject(ret)&&ret.statusCode == 0) {
                        toast("修改成功");

                        //退出登陆
                        logout();

                        //发送修改密码时间
                        api.sendEvent({
                            name: 'changePwdEvent'
                        });

                        //关闭该页面
                        closeWin();



                    }
                });
            }
        }
    };


</script>
</body>
</html>
